<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <el-card class="box-card">
    <h1 class="container">历史订单</h1>
    <div class="manage-header">
      <!-- form 搜索区域 -->
      <el-form
        :inline="true"
        :model="SearchForm"
        class="demo-form-inline"
        ref="searchFormRef"
        size="small"
      >
        <el-form-item label="时间范围" prop="time">
          <el-date-picker
            v-model="SearchTimeValue"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="菜名" prop="name">
          <el-input
            v-model="SearchForm.name"
            placeholder="请输入菜名"
          ></el-input>
        </el-form-item>
        <el-form-item label="订单状态" prop="type">
          <el-select v-model="SearchForm.type" placeholder="请选择状态">
            <el-option label="已接单" value="0"></el-option>
            <el-option label="制作中" value="1"></el-option>
            <el-option label="已完成" value="2"></el-option>
            <el-option label="已退单" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="onSearchClear('searchFormRef')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-table
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      style="width: 100%"
      align="center"
    >
      <el-table-column type="index" label="序号" :index="indexMethod">
      </el-table-column>

      <el-table-column prop="order_name" label="菜名"> </el-table-column>
      <el-table-column prop="price" label="价格"> </el-table-column>
      <el-table-column label="订单状态" prop="type">
        <template slot-scope="scope">
          <div>
            <el-tag :type="FoodColorMap(scope.row.type)">
              {{ FoodTypeMap(scope.row.type) }}
            </el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="more_mess" label="备注"> </el-table-column>
      <el-table-column prop="order_time" label="更新时间"> </el-table-column>
      <el-table-column prop="address" label="操作" width="280">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="onDetail(scope.row.ID)"
            icon="el-icon-receiving"
            >订单详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[2, 5, 10, 15]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page_num"
      >
      </el-pagination>
    </div>
    <!-- 抽屉 -->
    <el-drawer
      title="订单详情"
      :visible.sync="isDrawerVisible"
      :direction="direction"
      :before-close="handleDrawerClose"
    >
      <div class="drawer">
        <el-steps direction="vertical" :active="1">
          <el-step
            title="已接单"
            description="订单已接单，请注意查收"
          ></el-step>
          <el-step title="制作中" description="订单制作中"></el-step>
          <el-step
            title="已完成"
            description="订单已完成，请提醒顾客"
          ></el-step>
        </el-steps>
        <div class="drawer_neirong">
          <el-descriptions title="内容" direction="vertical" :column="2" border>
            <el-descriptions-item label="顾客">肖二拾</el-descriptions-item>
            <el-descriptions-item label="手机号"
              >18100000000</el-descriptions-item
            >
            <el-descriptions-item label="订单来源">
              <el-tag size="small">微信支付</el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="合计（元）">
              100元
            </el-descriptions-item>
            <el-descriptions-item label="备注" :span="2"
              >大哥不要辣椒</el-descriptions-item
            >
          </el-descriptions>
        </div>
      </div>
    </el-drawer>
  </el-card>
</template>
    
  
  
  <script>
export default {
  created() {
    this.page_num = this.tableData.length;
    this.getUserList();
  },
  data() {
    return {
      // 抽屉
      isDrawerVisible: false,
      direction: "rtl",

      disabled: false,
      typeList: [],
      // 编辑弹窗状态
      isEidtModelVisible: false,
      // 新增弹窗
      isAddModelVisible: false,
      labelPosition: "right",
      url: "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
      srcList: [
        "https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
        "https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg",
      ],
      // 订单信息
      tableData: [
        {
          order_time: "2024-11-20",
          order_name: "西兰花",
          price: 12,
          type: "1",
          more_mess: "不要辣椒",
        },
        {
          order_time: "2024-11-24",
          order_name: "回锅肉",
          price: 22,
          type: "2",
          more_mess: "不要辣椒",
        },
        {
          order_time: "2024-11-27",
          order_name: "手撕包菜",
          price: 9,
          type: "3",
          more_mess: "不要辣椒",
        },
      ],
      // 分页
      page_num: 0,
      pageSize: 10,
      currentPage: 1,
      // 搜索form
      SearchForm: {
        name: "",
        region: "",
        type: "",
        state: "",
      },
      // 编辑form
      EidtForm: {},
      // 新增form
      AddForm: {
        name: "",
        price: "",
        specil: "",
        image: "",
      },
      // 表单验证规则
      addRules: {
        name: [{ required: true, message: "请输入菜名" }],
        price: [{ required: true, message: "请输入价格" }],
        specil: [{ required: true, message: "请选择菜品特点" }],
      },
      editRules: {
        name: [{ required: true, message: "请输入菜名" }],
        price: [{ required: true, message: "请输入价格" }],
        specil: [{ required: true, message: "请选择特点" }],
      },
      // 搜索日期
      SearchTimeValue: [
        new Date(2000, 10, 10, 10, 10),
        new Date(2000, 10, 11, 10, 10),
      ],
    };
  },
  computed: {
    FoodTypeMap() {
      return (value) => {
        const data = {
          0: "已接单",
          1: "制作中",
          2: "已完成",
          3: "已退单",
        };
        return data[value];
      };
    },
    FoodColorMap() {
      return (value) => {
        const data = {
          0: "info",
          1: "warning",
          2: "success",
          3: "danger",
        };
        return data[value];
      };
    },
  },
  methods: {
    indexMethod(index) {
      return index + 1;
    },
    // 订单详细
    onDetail() {
      this.isDrawerVisible = true;
    },

    // 抽屉
    handleDrawerClose() {
      this.isDrawerVisible = false;
    },
    // 状态按钮
    changeSwitch(value) {
      console.log("value", value);
      this.$confirm("此操作将修改菜品状态, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: "true",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "修改成功!",
          });
          this.switchUrl();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消修改",
          });
          value.isSwitch = !value.isSwitch;
        });
    },
    switchUrl() {},
    //编辑图片
    handleRemove(file) {
      console.log(file);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleDownload(file) {
      console.log(file);
    },
    // 搜索
    onSearch() {
      console.log("搜索!");
    },
    // 分页
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      // console.log(`当前页: ${val}`);
    },
    // 刷新
    async getUserList() {
      // var business_name = window.localStorage.getItem("name");
      // const { data: res } = await this.$http.get(
      //   "/api/checkmenu?business_name=" + business_name
      // );
      // // console.log(res);
      // if (res.code !== 200) {
      //   this.$message.error("刷新失败");
      //   return;
      // }
      this.$message.success("刷新成功！");
      // this.tableData = res.data;
    },
    // 删除按钮
    onDelete(val) {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: "true",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          // 接口
          // this.delete(val);
          console.log("删除val", val);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    onEdit(val) {
      // console.log(val);
      this.EidtForm.id = val;
    },
    // 编辑
    async onEditBtn(val) {
      this.$refs.form.validate((valid) => {
        // valid的值为true的时候代表表单验证成功
        if (valid) {
          if (this.modelType === 0) {
            // 表示新增
            // 调用新增接口
            console.log("添加接口");
          } else {
            // 表示编辑
            // 调用编辑接口
            console.log("编辑接口");
          }
          // 后续对表单数据的处理
          // 关闭弹窗
          this.$refs.form.resetFields(); //提交表单的时候也同时清楚数据，该方法是表单验证自带的方法，下次打开表单就不会有上次存在的数据
          this.isAddModelVisible = false;
        }
      });
      this.$message.success("修改成功！", val);
      // this.EidtForm = {};
      this.getUserList();
    },
    // 删除
    async delete(val) {
      // console.log(val);
      // const { data: res } = await this.$http.post("/api/delete", {
      //   ID: val.ID,
      // });
      // // console.log(res);
      // if (res.code !== 200) {
      //   this.$message.error("删除失败！");
      //   return;
      // }
      this.$message.success("删除成功！", val);
      this.getUserList();
    },
    // 点击新增按钮出发的事件
    handAdd() {
      this.modelType = 0;
      this.isAddModelVisible = true;
    },
    cancel() {
      this.handleClose();
    },
    // el-dialog自带属性的方法，当弹窗关闭的时候就会调用该方法
    handleClose() {
      // 再次点开的时候,清空表单里面的数据
      this.$refs.form.resetFields();
      this.isAddModelVisible = false;
    },
    // 提交用户表单
    addSubmit() {
      this.$refs.form.validate((valid) => {
        // valid的值为true的时候代表表单验证成功
        if (valid) {
          if (this.modelType === 0) {
            // 表示新增
            // 调用新增接口
            console.log("添加接口");
          } else {
            // 表示编辑
            // 调用编辑接口
            console.log("编辑接口");
          }
          // 后续对表单数据的处理
          // 关闭弹窗
          this.$refs.form.resetFields(); //提交表单的时候也同时清楚数据，该方法是表单验证自带的方法，下次打开表单就不会有上次存在的数据
          this.isAddModelVisible = false;
        }
      });
    },
    // 搜索重置
    onSearchClear(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
    
  <style scoped>
.container {
  text-align: left;
}
.manage-header {
  display: flex;
  justify-content: space-between;
}
.block {
  margin-top: 20px;
}
.drawer {
  height: 250px;
  padding: 20px;
}
.drawer_neirong {
  margin-top: 20px;
}
</style>
    